package com.lhb.controller;

import com.lhb.pojo.BaseResp;
import com.lhb.pojo.TbPermission;
import com.lhb.pojo.Teacher;
import com.lhb.service.PermissionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author LiangHaiBo
 * @version 1.0
 * @date 2021.10.13 下午 17:31
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    PermissionService permissionService;

    @RequiresPermissions(value = {"SYSTEM_ROLE_AUTH"})
    @RequestMapping("/findAll")
    public BaseResp findAll(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit) {
        return permissionService.findAll(page, limit);

    }


    @RequestMapping("/findPermissionByRole")
    public BaseResp findPermissionByRole(@RequestParam("id") Integer roleid) {
        return permissionService.findByRole(roleid);
    }

    //修改
    @RequestMapping(value = "/updatePer", method = RequestMethod.POST)
    public BaseResp updatePer(@RequestBody TbPermission tbPermission) {
        return permissionService.updatePer(tbPermission);
    }

    //增加
    @RequestMapping(value = "/AddPermission", method = RequestMethod.POST)
    public BaseResp AddPermission(@RequestBody TbPermission tbPermission) {
        return permissionService.AddPermission(tbPermission);
    }

    @RequestMapping("/del")
    public BaseResp delete(@RequestParam("id") Integer id) {
        permissionService.deleteById(id);
        BaseResp baseResp = new BaseResp();
        baseResp.setCode(1);
        baseResp.setMsg("删除成功");
        return baseResp;
    }
}
